import { App, createVNode, VNode, render } from 'vue';
import LoadingBar from './loading-bar.vue';
export default {
  install(app: App) {
    console.log('loadingbar-pugin........');
    // 将视图转成虚拟dom的
    const vnode: VNode = createVNode(LoadingBar);
    // console.log('loadingbar-pugin_vnoe:', vnode);
    render(vnode, document.body);
    // 将插件定义到vue对象全局环境上
    app.config.globalProperties.$loadingBar = {
      startLoadingBar() {
        vnode.component?.exposed?.startLaoding();
      },
      endLoadingBar() {
        vnode.component?.exposed?.endLoading();
      }
    };
    window.loadingBar = {
      startLoadingBar() {
        vnode.component?.exposed?.startLaoding();
      },
      endLoadingBar() {
        vnode.component?.exposed?.endLoading();
      }
    }
  }
}